import 'package:ft_reader/beans/category_item_bean.dart';
import 'package:ft_reader/blocs/base_bloc.dart';
import 'package:rxdart/rxdart.dart';

class CategoryBloc extends BaseBloc {

  final _categorysFetcher = PublishSubject<List<CategoryItemBean>>();

  // 监听
  Observable<List<CategoryItemBean>> get categoryItems => _categorysFetcher.stream;

  void fetchCategoryItems() async {
    List<CategoryItemBean> datas = await netApi.fetchCategoryData();
    if (!_categorysFetcher.isClosed) {
      _categorysFetcher.sink.add(datas);
    }
  }


  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _categorysFetcher?.close();
  }
}